package org.carl.dual.asyn;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;

import org.carl.dual.ThreadHelper;

public class HasReturn {
	public static void main(String[] args) {
		List<Callable<?>> callables=new ArrayList<>();
		callables.add(new Callable<Object>() {
			@Override
			public Object call() throws Exception {
				Thread.sleep(6000);
				return Thread.currentThread().getName()+"任务1 时间"+System.currentTimeMillis();
			}
		});
		callables.add(new Callable<Object>() {
			@Override
			public Object call() throws Exception {
				Thread.sleep(15000);
				return Thread.currentThread().getName()+"任务2 时间"+System.currentTimeMillis();
			}
		});
		callables.add(new Callable<Object>() {
			@Override
			public Object call() throws Exception {
				Thread.sleep(8000);
				return Thread.currentThread().getName()+"任务3 时间"+System.currentTimeMillis();
			}
		});
		List<Future<?>> futures=ThreadHelper.submit(callables, true);
		futures.forEach((a)->{
			try {
				System.out.println(a.get());
			} catch (Exception e) {
				e.printStackTrace();
			}
		});
	}
}
